<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>主页面</title>
</head>
<body>
 导入excel文件<input id="execl" type="file"> <button type="button" onclick="importExcel()">提交</button><br>
 <!--<div><a href="/addExcel" th:href="@{/addExcel}">导出用户信息</a></div>-->
<div><a href="/export" th:href="@{/export}">导出execl文件</a></div>
 <table border="1">
     <tr>
         <th>
           全选<input type="checkbox" style="width: 10px" height="10px" onchange="checkAll()" id="chkAll">
         </th>
         <th>编号</th>
         <th>eid</th>
         <th>openid</th>
         <th>昵称</th>
         <th>性别</th>
         <th>城市</th>
         <th>国家</th>
         <th>省份</th>
         <th>头像地址</th>
         <th>状态</th>
         <th>语言</th>
         <th>备注</th>
         <th>操作</th>
     </tr>


             <tr th:each="p:${pageInfo.list }" >
                 <td><input type="checkbox" style="width: 10px" height="10px" onchange="check(this)" name="ids" th:value="${p.id}"></td>
                 <td th:text="${p.id}"></td>
                 <td th:text="${p.eid }"></td>
                 <td th:text="${p.openid }"></td>
                 <td th:text="${p.nickname }"></td>
                 <td th:if="${p.sex==1}">
                     男
                 </td>
                 <td th:if="${p.sex==0}">
                     女
                 </td>
                 <td th:if="${p.sex==2}">
                     无
                 </td>
                 <td th:text="${p.city }"></td>
                 <td th:text="${p.country }"></td>
                 <td th:text="${p.province }"></td>
                 <td th:text="${p.headimgurl }"></td>
                 <td th:text="${p.subscribe }"></td>
                 <td th:text="${p.language }"></td>
                 <td th:text="${p.remark }"></td>

                 <td>
                     <button type="button" th:onclick="|javascript:delOne(${p.id})|" >删除</button>
                 </td>
             </tr>



 </table>
 <button type="button" onclick="delAll()">删除选中</button>
 总共<span th:text="${pageInfo.total}"></span>记录，总共<span th:text="${pageInfo.pages}"></span>页
 <span th:if="${pageInfo.hasPreviousPage==true}">
          <a href="/tomain?pageNum" th:href="@{|/tomain?pageNum=${pageInfo.prePage}|}">上一页</a>
     </span>
 <span th:if="${pageInfo.hasPreviousPage==false}">
         <a href="/tomain?pageNum" th:href="@{|/tomain?pageNum=${pageInfo.navigateLastPage}|}">上一页</a>
     </span>

 <a href="tomain?pageNum=1">第一页</a><a href="tomain?pageNum=2">第二页</a><a href="tomain?pageNum=3">第三页</a>


 <span th:if="${pageInfo.hasNextPage==true}">
          <a href="/tomain?pageNum=" th:href="@{|/tomain?pageNum=${pageInfo.nextPage}|}">下一页</a>
     </span>
 <span th:if="${pageInfo.hasNextPage==false}">
         <a href="/tomain?pageNum=" th:href="@{|/tomain?pageNum=${pageInfo.navigateFirstPage}|}">下一页</a>
     </span>
<a href="/selExcel" th:href="@{/selExcel}">跳转查询页面</a>
</body>
<script src="https://cdn.bootcdn.net/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script type="text/javascript">
function importExcel() {
    var file = $('#execl')[0].files[0];
    var formData  = new FormData();
    formData.append("fileExcel",file);
   /*var uploadFile = new FormData($("#file")[0]);*/
    if("undefined" != typeof(file) && file != null && file != "") {

        $.ajax({
            url: '[[@{/addExcel}]]',
            type: 'POST',
            data: formData,
            async: false,
            cache: false,
            contentType: false, //不设置内容类型
            processData: false, //不处理数据

            success: function (data) {
                if (data.code==1){
                    alert(data.message)
                }else {
                    alert(data.message)
                }
            }
        })
    }else {
        alert("选择的文件无效！请重新选择");
    }
}

function delOne(sid) {
    var id=0;
    if(sid!=undefined) {
        id =sid;
        $.ajax({
            url:"delOne",
            type:"post",
            data:{"id":id},
            dataType:"json",
            success:function(data){
                if(data.code==1){
                    alert(data.message)
                    location.href="[[@{/tomain}]]"
                }else {
                    alert(data.message)

                }
            }
        })
    }
}

 function checkAll() {
     //获取我们全选按钮的选中的状态;
     var ck = $("#chkAll").prop("checked");

     //修改我们所有名字为tck的复选框的状态
     $("input[name='ids']").prop("checked", ck);

 }


 function check(obj) {
     $("#chkAll").prop("checked", $("input[name='ids']").length == $("input[name='ids']:checked").length);
 }

 function delAll() {
     var ids = $("input[name='ids']:checked").map(function () {
         return $(this).val();
     }).get().join(',');
     console.info(ids)
         $.ajax({
             url:"delAll",
             type:"post",
             data:{"ids":ids},
             dataType:"json",
             success:function(data){
                 if(data.code==1){
                     alert(data.message)
                     location.href="[[@{/tomain}]]"
                 }else {
                     alert(data.message)

                 }
             }
         })
 }

</script>
</html>